home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / yacc.lbr / y-tab.c < prev    next >
Text File  |  2011-02-03  |  23KB  |  1,007 lines

  1. #define CHAR 257
  2. #define CCL 258
  3. #define NCCL 259
  4. #define STR 260
  5. #define DELIM 261
  6. #define SCON 262
  7. #define ITER 263
  8. #define NEWE 264
  9. #define NULLS 265
  10. #define CAT 266
  11.  
  12. #include "c:ldefs.c"
  13. #define yyclearin yychar = -1
  14. #define yyerrok yyerrflag = 0
  15. extern int yychar;
  16. extern short yyerrflag;
  17. #ifndef YYMAXDEPTH
  18. #define YYMAXDEPTH 150
  19. #endif
  20. #ifndef YYSTYPE
  21. #define YYSTYPE int
  22. #endif
  23. YYSTYPE yylval, yyval;
  24.  
  25. int i;
  26. int j,k;
  27. int g;
  28. char *p;
  29. #define YYERRCODE 256
  30.  
  31.  
  32. yylex(){
  33.     register char *p;
  34.     register int c, i;
  35.     char  *t, *xp;
  36.     int n, j, k, x;
  37.     static int sectbegin;
  38.     static char token[TOKENSIZE];
  39.     static int iter;
  40.  
  41. # ifdef DEBUG
  42.     yylval = 0;
  43. # endif
  44.  
  45.     if(sect == DEFSECTION) {        /* definitions section */
  46.         while(!eof) {
  47.             if(prev == '\n'){        /* next char is at begin
  48. ning of line */
  49.                 getl(p=buf);
  50.                 switch(*p){
  51.                 case '%':
  52.                     switch(c= *(p+1)){
  53.                     case '%':
  54.                         lgate();
  55.                         if(!ratfor)fprintf(fout,"# ");
  56.                         fprintf(fout,"define YYNEWLINE %
  57. d\n",ctable['\n']);
  58.                         if(!ratfor)fprintf(fout,"yylex()
  59. {\nint nstr; extern int yyprevious;\n");
  60.                         sectbegin = TRUE;
  61.                         i = treesize*(sizeof(*name)+size
  62. of(*left)+
  63.                             sizeof(*right)+sizeof(*n
  64. ullstr)+sizeof(*parent))+ALITTLEEXTRA;
  65.                         c = myalloc(i,1);
  66.                         if(c == 0)
  67.                             error("Too little core f
  68. or parse tree");
  69.                         p = c;
  70.                         cfree(p,i,1);
  71.                         name = myalloc(treesize,sizeof(*
  72. name));
  73.                         left = myalloc(treesize,sizeof(*
  74. left));
  75.                         right = myalloc(treesize,sizeof(
  76. *right));
  77.                         nullstr = myalloc(treesize,sizeo
  78. f(*nullstr));
  79.                         parent = myalloc(treesize,sizeof
  80. (*parent));
  81.                         if(name == 0 || left == 0 || rig
  82. ht == 0 || parent == 0 || nullstr == 0)
  83.                             error("Too little core f
  84. or parse tree");
  85.                         return(freturn(DELIM));
  86.                     case 'p': case 'P':    /* has overridde
  87. n number of positions */
  88.                         while(*p && !digit(*p))p++;
  89.                         maxpos = siconv(p);
  90. # ifdef DEBUG
  91.                         if (debug) printf("positions (%%
  92. p) now %d\n",maxpos);
  93. # endif
  94.                         if(report == 2)report = 1;
  95.                         continue;
  96.                     case 'n': case 'N':    /* has overridde
  97. n number of states */
  98.                         while(*p && !digit(*p))p++;
  99.                         nstates = siconv(p);
  100. # ifdef DEBUG
  101.                         if(debug)printf( " no. states (%
  102. %n) now %d\n",nstates);
  103. # endif
  104.                         if(report == 2)report = 1;
  105.                         continue;
  106.                     case 'e': case 'E':        /* has o
  107. verridden number of tree nodes */
  108.                         while(*p && !digit(*p))p++;
  109.                         treesize = siconv(p);
  110. # ifdef DEBUG
  111.                         if (debug) printf("treesize (%%e
  112. ) now %d\n",treesize);
  113. # endif
  114.                         if(report == 2)report = 1;
  115.                         continue;
  116.                     case 'o': case 'O':
  117.                         while (*p && !digit(*p))p++;
  118.                         outsize = siconv(p);
  119.                         if (report ==2) report=1;
  120.                         continue;
  121.                     case 'a': case 'A':        /* has o
  122. verridden number of transitions */
  123.                         while(*p && !digit(*p))p++;
  124.                         if(report == 2)report = 1;
  125.                         ntrans = siconv(p);
  126. # ifdef DEBUG
  127.                         if (debug)printf("N. trans (%%a)
  128.  now %d\n",ntrans);
  129. # endif
  130.                         continue;
  131.                     case 'k': case 'K': /* overriden packed 
  132. char classes */
  133.                         while (*p && !digit(*p))p++;
  134.                         if (report==2) report=1;
  135.                         cfree(pchar, pchlen, sizeof(*pch
  136. ar));
  137.                         pchlen = siconv(p);
  138. # ifdef DEBUG
  139.                         if (debug) printf( "Size classes
  140.  (%%k) now %d\n",pchlen);
  141. # endif
  142.                         pchar=pcptr=myalloc(pchlen, size
  143. of(*pchar));
  144.                         continue;
  145.                     case 't': case 'T':     /* character set
  146.  specifier */
  147.                         ZCH = atoi(p+2);
  148.                         if (ZCH < NCH) ZCH = NCH;
  149.                         if (ZCH > 2*NCH) error("ch table
  150.  needs redeclaration");
  151.                         chset = TRUE;
  152.                         for(i = 0; i<ZCH; i++)
  153.                             ctable[i] = 0;
  154.                         while(getl(p) && scomp(p,"%T") !
  155. = 0 && scomp(p,"%t") != 0){
  156.                             if((n = siconv(p)) <= 0 
  157. || n > ZCH){
  158.                                 warning("Charact
  159. er value %d out of range",n);
  160.                                 continue;
  161.                                 }
  162.                             while(!space(*p) && *p) 
  163. p++;
  164.                             while(space(*p)) p++;
  165.                             t = p;
  166.                             while(*t){
  167.                                 c = ctrans(&t);
  168.                                 if(ctable[c]){
  169.                                     if (prin
  170. table(c))
  171.                                         w
  172. arning("Character '%c' used twice",c);
  173.                                     else
  174.                                         w
  175. arning("Character %o used twice",c);
  176.                                     }
  177.                                 else ctable[c] =
  178.  n;
  179.                                 t++;
  180.                                 }
  181.                             p = buf;
  182.                             }
  183.                         {
  184.                         char chused[2*NCH]; int kr;
  185.                         for(i=0; i<ZCH; i++)
  186.                             chused[i]=0;
  187.                         for(i=0; i<NCH; i++)
  188.                             chused[ctable[i]]=1;
  189.                         for(kr=i=1; i<NCH; i++)
  190.                             if (ctable[i]==0)
  191.                                 {
  192.                                 while (chused[kr
  193. ] == 0)
  194.                                     kr++;
  195.                                 ctable[i]=kr;
  196.                                 chused[kr]=1;
  197.                                 }
  198.                         }
  199.                         lgate();
  200.                         continue;
  201.                     case 'r': case 'R':
  202.                         c = 'r';
  203.                     case 'c': case 'C':
  204.                         if(lgatflg)
  205.                             error("Too late for lang
  206. uage specifier");
  207.                         ratfor = (c == 'r');
  208.                         continue;
  209.                     case '{':
  210.                         lgate();
  211.                         while(getl(p) && scomp(p,"%}") !
  212. = 0)
  213.                             fprintf(fout, "%s\n",p);
  214.                         if(p[0] == '%') continue;
  215.                         error("Premature eof");
  216.                     case 's': case 'S':        /* start
  217.  conditions */
  218.                         lgate();
  219.                         while(*p && index(*p," \t,") < 0
  220. ) p++;
  221.                         n = TRUE;
  222.                         while(n){
  223.                             while(*p && index(*p," \
  224. t,") >= 0) p++;
  225.                             t = p;
  226.                             while(*p && index(*p," \
  227. t,") < 0)p++;
  228.                             if(!*p) n = FALSE;
  229.                             *p++ = 0;
  230.                             if (*t == 0) continue;
  231.                             i = sptr*2;
  232.                             if(!ratfor)fprintf(fout,
  233. "# ");
  234.                             fprintf(fout,"define %s 
  235. %d\n",t,i);
  236.                             scopy(t,sp);
  237.                             sname[sptr++] = sp;
  238.                             sname[sptr] = 0;    /
  239. * required by lookup */
  240.                             if(sptr >= STARTSIZE)
  241.                                 error("Too many 
  242. start conditions");
  243.                             sp += slength(sp) + 1;
  244.                             if(sp >= schar+STARTCHAR
  245. )
  246.                                 error("Start con
  247. ditions too long");
  248.                             }
  249.                         continue;
  250.                     default:
  251.                         warning("Invalid request %s",p);
  252.                         continue;
  253.                         }    /* end of switch after s
  254. eeing '%' */
  255.                 case ' ': case '\t':        /* must be code 
  256. */
  257.                     lgate();
  258.                     fprintf(fout, "%s\n",p);
  259.                     continue;
  260.                 default:        /* definition */
  261.                     while(*p && !space(*p)) p++;
  262.                     if(*p == 0)
  263.                         continue;
  264.                     prev = *p;
  265.                     *p = 0;
  266.                     bptr = p+1;
  267.                     yylval = buf;
  268.                     if(digit(buf[0]))
  269.                         warning("Substitution strings ma
  270. y not begin with digits");
  271.                     return(freturn(STR));
  272.                     }
  273.                 }
  274.             /* still sect 1, but prev != '\n' */
  275.             else {
  276.                 p = bptr;
  277.                 while(*p && space(*p)) p++;
  278.                 if(*p == 0)
  279.                     warning("No translation given - null str
  280. ing assumed");
  281.                 scopy(p,token);
  282.                 yylval = token;
  283.                 prev = '\n';
  284.                 return(freturn(STR));
  285.                 }
  286.             }
  287.         /* end of section one processing */
  288.         }
  289.     else if(sect == RULESECTION){        /* rules and actions */
  290.         while(!eof){
  291.             switch(c=gch()){
  292.             case '\0':
  293.                 return(freturn(0));
  294.             case '\n':
  295.                 if(prev == '\n') continue;
  296.                 x = NEWE;
  297.                 break;
  298.             case ' ':
  299.             case '\t':
  300.                 if(sectbegin == TRUE){
  301.                     cpyact();
  302.                     while((c=gch()) && c != '\n');
  303.                     continue;
  304.                     }
  305.                 if(!funcflag)phead2();
  306.                 funcflag = TRUE;
  307.                 if(ratfor)fprintf(fout,"%d\n",30000+casecount);
  308.                 else fprintf(fout,"case %d:\n",casecount);
  309.                 if(cpyact()){
  310.                     if(ratfor)fprintf(fout,"goto 30997\n");
  311.                     else fprintf(fout,"break;\n");
  312.                     }
  313.                 while((c=gch()) && c != '\n');
  314.                 if(peek == ' ' || peek == '\t' || sectbegin == T
  315. RUE){
  316.                     warning("Executable statements should oc
  317. cur right after %%");
  318.                     continue;
  319.                     }
  320.                 x = NEWE;
  321.                 break;
  322.             case '%':
  323.                 if(prev != '\n') goto character;
  324.                 if(peek == '{'){    /* included code */
  325.                     getl(buf);
  326.                     while(!eof && getl(buf) && scomp("%}",bu
  327. f) != 0)
  328.                         fprintf(fout,"%s\n",buf);
  329.                     continue;
  330.                     }
  331.                 if(peek == '%'){
  332.                     c = gch();
  333.                     c = gch();
  334.                     x = DELIM;
  335.                     break;
  336.                     }
  337.                 goto character;
  338.             case '|':
  339.                 if(peek == ' ' || peek == '\t' || peek == '\n'){
  340.                     if(ratfor)fprintf(fout,"%d\n",30000+case
  341. count++);
  342.                     else fprintf(fout,"case %d:\n",casecount
  343. ++);
  344.                     continue;
  345.                     }
  346.                 x = '|';
  347.                 break;
  348.             case '$':
  349.                 if(peek == '\n' || peek == ' ' || peek == '\t' |
  350. | peek == '|' || peek == '/'){
  351.                     x = c;
  352.                     break;
  353.                     }
  354.                 goto character;
  355.             case '^':
  356.                 if(prev != '\n' && scon != TRUE) goto character;
  357.     /* valid only at line begin */
  358.                 x = c;
  359.                 break;
  360.             case '?':
  361.             case '+':
  362.             case '.':
  363.             case '*':
  364.             case '(':
  365.             case ')':
  366.             case ',':
  367.             case '/':
  368.                 x = c;
  369.                 break;
  370.             case '}':
  371.                 iter = FALSE;
  372.                 x = c;
  373.                 break;
  374.             case '{':    /* either iteration or definition */
  375.                 if(digit(c=gch())){    /* iteration */
  376.                     iter = TRUE;
  377.                 ieval:
  378.                     i = 0;
  379.                     while(digit(c)){
  380.                         token[i++] = c;
  381.                         c = gch();
  382.                         }
  383.                     token[i] = 0;
  384.                     yylval = siconv(token);
  385.                     munput('c',c);
  386.                     x = ITER;
  387.                     break;
  388.                     }
  389.                 else {        /* definition */
  390.                     i = 0;
  391.                     while(c && c!='}'){
  392.                         token[i++] = c;
  393.                         c = gch();
  394.                         }
  395.                     token[i] = 0;
  396.                     i = lookup(token,def);
  397.                     if(i < 0)
  398.                         warning("Definition %s not found
  399. ",token);
  400.                     else
  401.                         munput('s',subs[i]);
  402.                     continue;
  403.                     }
  404.             case '<':        /* start condition ? */
  405.                 if(prev != '\n')        /* not at line b
  406. egin, not start */
  407.                     goto character;
  408.                 t = slptr;
  409.                 do {
  410.                     i = 0;
  411.                     c = gch();
  412.                     while(c != ',' && c && c != '>'){
  413.                         token[i++] = c;
  414.                         c = gch();
  415.                         }
  416.                     token[i] = 0;
  417.                     if(i == 0)
  418.                         goto character;
  419.                     i = lookup(token,sname);
  420.                     if(i < 0) {
  421.                         warning("Undefined start conditi
  422. on %s",token);
  423.                         continue;
  424.                         }
  425.                     *slptr++ = i+1;
  426.                     } while(c && c != '>');
  427.                 *slptr++ = 0;
  428.                 /* check if previous value re-usable */
  429.                 for (xp=slist; xp<t; )
  430.                     {
  431.                     if (strcmp(xp, t)==0)
  432.                         break;
  433.                     while (*xp++);
  434.                     }
  435.                 if (xp<t)
  436.                     {
  437.                     /* re-use previous pointer to string */
  438.                     slptr=t;
  439.                     t=xp;
  440.                     }
  441.                 if(slptr > slist+STARTSIZE)        /* note 
  442. not packed ! */
  443.                     error("Too many start conditions used");
  444.                 yylval = t;
  445.                 x = SCON;
  446.                 break;
  447.             case '"':
  448.                 i = 0;
  449.                 while((c=gch()) && c != '"' && c != '\n'){
  450.                     if(c == '\\') c = usescape(c=gch());
  451.                     token[i++] = c;
  452.                     if(i > TOKENSIZE){
  453.                         warning("String too long");
  454.                         i = TOKENSIZE-1;
  455.                         break;
  456.                         }
  457.                     }
  458.                 if(c == '\n') {
  459.                     yyline--;
  460.                     warning("Non-terminated string");
  461.                     yyline++;
  462.                     }
  463.                 token[i] = 0;
  464.                 if(i == 0)x = NULLS;
  465.                 else if(i == 1){
  466.                     yylval = token[0];
  467.                     x = CHAR;
  468.                     }
  469.                 else {
  470.                     yylval = token;
  471.                     x = STR;
  472.                     }
  473.                 break;
  474.             case '[':
  475.                 for(i=1;i<NCH;i++) symbol[i] = 0;
  476.                 x = CCL;
  477.                 if((c = gch()) == '^'){
  478.                     x = NCCL;
  479.                     c = gch();
  480.                     }
  481.                 while(c != ']' && c){
  482.                     if(c == '\\') c = usescape(c=gch());
  483.                     symbol[c] = 1;
  484.                     j = c;
  485.                     if((c=gch()) == '-' && peek != ']'){        /
  486. * range specified */
  487.                         c = gch();
  488.                         if(c == '\\') c = usescape(c=gch
  489. ());
  490.                         k = c;
  491.                         if(j > k) {
  492.                             n = j;
  493.                             j = k;
  494.                             k = n;
  495.                             }
  496.                         if(!(('A' <= j && k <= 'Z') ||
  497.                              ('a' <= j && k <= 'z') ||
  498.                              ('0' <= j && k <= '9')))
  499.                             warning("Non-portable Ch
  500. aracter Class");
  501.                         for(n=j+1;n<=k;n++)
  502.                             symbol[n] = 1;        /
  503. * implementation dependent */
  504.                         c = gch();
  505.                         }
  506.                     }
  507.                 /* try to pack ccl's */
  508.                 i = 0;
  509.                 for(j=0;j<NCH;j++)
  510.                     if(symbol[j])token[i++] = j;
  511.                 token[i] = 0;
  512.                 p = ccptr;
  513.                 if(optim){
  514.                     p = ccl;
  515.                     while(p <ccptr && scomp(token,p) != 0)p+
  516. +;
  517.                     }
  518.                 if(p < ccptr)    /* found it */
  519.                     yylval = p;
  520.                 else {
  521.                     yylval = ccptr;
  522.                     scopy(token,ccptr);
  523.                     ccptr += slength(token) + 1;
  524.                     if(ccptr >= ccl+CCLSIZE)
  525.                         error("Too many large character 
  526. classes");
  527.                     }
  528.                 cclinter(x==CCL);
  529.                 break;
  530.             case '\\':
  531.                 c = usescape(c=gch());
  532.             default:
  533.             character:
  534.                 if(iter){    /* second part of an iteration *
  535. /
  536.                     iter = FALSE;
  537.                     if('0' <= c && c <= '9')
  538.                         goto ieval;
  539.                     }
  540.                 if(alpha(peek)){
  541.                     i = 0;
  542.                     yylval = token;
  543.                     token[i++] = c;
  544.                     while(alpha(peek))
  545.                         token[i++] = gch();
  546.                     if(peek == '?' || peek == '*' || peek ==
  547.  '+')
  548.                         munput('c',token[--i]);
  549.                     token[i] = 0;
  550.                     if(i == 1){
  551.                         yylval = token[0];
  552.                         x = CHAR;
  553.                         }
  554.                     else x = STR;
  555.                     }
  556.                 else {
  557.                     yylval = c;
  558.                     x = CHAR;
  559.                     }
  560.                 }
  561.             scon = FALSE;
  562.             if(x == SCON)scon = TRUE;
  563.             sectbegin = FALSE;
  564.             return(freturn(x));
  565.             }
  566.         }
  567.     /* section three */
  568.     ptail();
  569. # ifdef DEBUG
  570.     if(debug)
  571.         fprintf(fout,"\n/*this comes from section three - debug */\n");
  572. # endif
  573.     while(getl(buf) && !eof)
  574.         fprintf(fout,"%s\n",buf);
  575.     return(freturn(0));
  576.     }
  577. /* end of yylex */
  578. # ifdef DEBUG
  579. freturn(i)
  580.   int i; {
  581.     if(yydebug) {
  582.         printf("now return ");
  583.         if(i < NCH) allprint(i);
  584.         else printf("%d",i);
  585.         printf("   yylval = ");
  586.         switch(i){
  587.             case STR: case CCL: case NCCL:
  588.                 strpt(yylval);
  589.                 break;
  590.             case CHAR:
  591.                 allprint(yylval);
  592.                 break;
  593.             default:
  594.                 printf("%d",yylval);
  595.                 break;
  596.             }
  597.         putchar('\n');
  598.         }
  599.     return(i);
  600.     }
  601. # endif
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612. short yyexca[] ={
  613. -1, 1,
  614.     0, -1,
  615.     -2, 0,
  616.     };
  617. #define YYNPROD 33
  618. #define YYLAST 291
  619. short yyact[]={
  620.  
  621.   34,  45,  35,  23,  21,  43,  27,  28,   4,  34,
  622.   16,  32,  41,  21,  46,  27,  28,  10,  34,  16,
  623.   32,   8,  21,   9,  27,  28,  25,  29,  16,   6,
  624.    7,   3,  24,  34,  27,  28,  29,  21,  11,  27,
  625.   28,   2,   5,  16,   1,  29,  21,   0,  27,  28,
  626.    0,   0,  16,   0,   0,  29,  21,   0,  20,   0,
  627.   29,   0,  16,   0,   0,  21,   0,  20,   0,  29,
  628.    0,  16,   0,   0,  31,   0,  20,   0,   0,   0,
  629.   12,   0,   0,  12,   0,   0,   0,   0,  30,   0,
  630.    0,  20,   0,  42,  36,  37,  38,  30,   0,   0,
  631.    0,   0,   0,   0,   0,  39,  30,  40,   0,   0,
  632.   20,   0,   0,   0,   0,   0,   0,   0,   0,  20,
  633.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  634.    0,   0,   0,   0,   0,   0,   0,   0,   0,  44,
  635.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  636.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  637.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  638.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  639.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  640.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  641.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  642.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  643.    0,  14,  17,  18,  15,   0,  19,  33,   0,  22,
  644.   14,  17,  18,  15,   0,  19,  33,  26,  22,  14,
  645.   17,  18,  15,   0,   0,  33,   0,  22,   0,   0,
  646.    0,   0,   0,   0,  14,  17,  18,  15,   0,   0,
  647.   33,   0,  22,  14,  17,  18,  15,   0,   0,  33,
  648.    0,  22,  13,  14,  17,  18,  15,   7,  19,   0,
  649.    0,  22,  14,  17,  18,  15,   0,  19,   0,   0,
  650.   22 };
  651. short yypact[]={
  652.  
  653. -248,-1000,-1000,-231,-1000,  16,-257,-1000,  16,-1000,
  654. -1000,-1000, -27,-262,-1000,-1000,-1000,-1000,-1000,  25,
  655.   25,  25,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
  656.   25,  -8,  25, -32,-1000,-1000, -18,   6, -36,  -3,
  657.  -18,-124,-1000,-1000,-111,-1000,-1000 };
  658. short yypgo[]={
  659.  
  660.    0,  44,  41,  31,  38,  21,  23,  17,  74 };
  661. short yyr1[]={
  662.  
  663.    0,   1,   2,   2,   2,   6,   6,   3,   3,   4,
  664.    5,   5,   7,   7,   8,   8,   8,   8,   8,   8,
  665.    8,   8,   8,   8,   8,   8,   8,   8,   8,   8,
  666.    8,   8,   8 };
  667. short yyr2[]={
  668.  
  669.    0,   1,   4,   3,   1,   1,   0,   3,   0,   1,
  670.    2,   1,   2,   2,   1,   1,   1,   1,   1,   2,
  671.    2,   2,   3,   2,   3,   5,   3,   4,   2,   2,
  672.    2,   3,   1 };
  673. short yychk[]={
  674.  
  675. -1000,  -1,  -2,  -3, 256,  -4, 260, 261,  -5,  -6,
  676.   -7,  -4,  -8, 256, 257, 260,  46, 258, 259, 262,
  677.   94,  40, 265, 260,  -6,  -7, 264,  42,  43,  63,
  678.  124,  -8,  47, 263,  36, 264,  -8,  -8,  -8,  -8,
  679.   -8,  44, 125,  41, 263, 125, 125 };
  680. short yydef[]={
  681.  
  682.    8,  -2,   1,   0,   4,   6,   0,   9,   6,   3,
  683.   11,   5,   0,   0,  14,  15,  16,  17,  18,   0,
  684.    0,   0,  32,   7,   2,  10,  12,  19,  20,  21,
  685.    0,  23,   0,   0,  30,  13,  28,  29,   0,  22,
  686.   24,   0,  26,  31,   0,  27,  25 };
  687. #define YYFLAG -1000
  688. #define YYERROR goto yyerrlab
  689. #define YYACCEPT return(0)
  690. #define YYABORT return(1)
  691.  
  692. /*    parser for yacc output    */
  693.  
  694. int yydebug = 0; /* 1 for debugging */
  695. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  696. int yychar = -1; /* current input token number */
  697. int yynerrs = 0;  /* number of errors */
  698. short yyerrflag = 0;  /* error recovery flag */
  699.  
  700. yyparse() {
  701.  
  702.     short yys[YYMAXDEPTH];
  703.     short yyj, yym;
  704.     register YYSTYPE *yypvt;
  705.     register short yystate, *yyps, yyn;
  706.     register YYSTYPE *yypv;
  707.     register short *yyxi;
  708.  
  709.     yystate = 0;
  710.     yychar = -1;
  711.     yynerrs = 0;
  712.     yyerrflag = 0;
  713.     yyps= &yys[-1];
  714.     yypv= &yyv[-1];
  715.  
  716.  yystack:    /* put a state and value onto the stack */
  717.  
  718.     if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
  719.         if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
  720.         *yyps = yystate;
  721.         ++yypv;
  722.         *yypv = yyval;
  723.  
  724.  yynewstate:
  725.  
  726.     yyn = yypact[yystate];
  727.  
  728.     if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  729.  
  730.     if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  731.     if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  732.  
  733.     if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  734.         yychar = -1;
  735.         yyval = yylval;
  736.         yystate = yyn;
  737.         if( yyerrflag > 0 ) --yyerrflag;
  738.         goto yystack;
  739.         }
  740.  
  741.  yydefault:
  742.     /* default state action */
  743.  
  744.     if( (yyn=yydef[yystate]) == -2 ) {
  745.         if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  746.         /* look through exception table */
  747.  
  748.         for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  749.  
  750.         while( *(yyxi+=2) >= 0 ){
  751.             if( *yyxi == yychar ) break;
  752.             }
  753.         if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
  754.         }
  755.  
  756.     if( yyn == 0 ){ /* error */
  757.         /* error ... attempt to resume parsing */
  758.  
  759.         switch( yyerrflag ){
  760.  
  761.         case 0:   /* brand new error */
  762.  
  763.             yyerror( "syntax error" );
  764.         yyerrlab:
  765.             ++yynerrs;
  766.  
  767.         case 1:
  768.         case 2: /* incompletely recovered error ... try again */
  769.  
  770.             yyerrflag = 3;
  771.  
  772.             /* find a state where "error" is a legal shift action */
  773.  
  774.             while ( yyps >= yys ) {
  775.                yyn = yypact[*yyps] + YYERRCODE;
  776.                if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  777.                   yystate = yyact[yyn];  /* simulate a shift of "error" */
  778.                   goto yystack;
  779.                   }
  780.                yyn = yypact[*yyps];
  781.  
  782.                /* the current yyps has no shift onn "error", pop stack */
  783.  
  784.                if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  785.                --yyps;
  786.                --yypv;
  787.                }
  788.  
  789.             /* there is no state on the stack with an error shift ... abort */
  790.  
  791.     yyabort:
  792.             return(1);
  793.  
  794.  
  795.         case 3:  /* no shift yet; clobber input char */
  796.  
  797.             if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  798.  
  799.             if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  800.             yychar = -1;
  801.             goto yynewstate;   /* try again in the same state */
  802.  
  803.             }
  804.  
  805.         }
  806.  
  807.     /* reduction by production yyn */
  808.  
  809.         if( yydebug ) printf("reduce %d\n",yyn);
  810.         yyps -= yyr2[yyn];
  811.         yypvt = yypv;
  812.         yypv -= yyr2[yyn];
  813.         yyval = yypv[1];
  814.         yym=yyn;
  815.             /* consult goto table to find next state */
  816.         yyn = yyr1[yyn];
  817.         yyj = yypgo[yyn] + *yyps + 1;
  818.         if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  819.         switch(yym){
  820.             
  821. case 1:
  822. {    
  823. # ifdef DEBUG
  824.         if(debug) sect2dump();
  825. # endif
  826.     } break;
  827. case 3:
  828. {
  829.         if(!funcflag)phead2();
  830.         funcflag = TRUE;
  831.     } break;
  832. case 4:
  833. {
  834. # ifdef DEBUG
  835.         if(debug) {
  836.             sect1dump();
  837.             sect2dump();
  838.             }
  839. # endif
  840.         } break;
  841. case 7:
  842. {    scopy(yypvt[-1],dp);
  843.         def[dptr] = dp;
  844.         dp += slength(yypvt[-1]) + 1;
  845.         scopy(yypvt[-0],dp);
  846.         subs[dptr++] = dp;
  847.         if(dptr >= DEFSIZE)
  848.             error("Too many definitions");
  849.         dp += slength(yypvt[-0]) + 1;
  850.         if(dp >= dchar+DEFCHAR)
  851.             error("Definitions too long");
  852.         subs[dptr]=def[dptr]=0;    /* for lookup - require ending null */
  853.     } break;
  854. case 9:
  855. {
  856. # ifdef DEBUG
  857.         if(sect == DEFSECTION && debug) sect1dump();
  858. # endif
  859.         sect++;
  860.         } break;
  861. case 10:
  862. {    yyval = mn2(RNEWE,yypvt[-1],yypvt[-0]);
  863.         } break;
  864. case 11:
  865. {    yyval = yypvt[-0];} break;
  866. case 12:
  867. {
  868.         if(divflg == TRUE)
  869.             i = mn1(S1FINAL,casecount);
  870.         else i = mn1(FINAL,casecount);
  871.         yyval = mn2(RCAT,yypvt[-1],i);
  872.         divflg = FALSE;
  873.         casecount++;
  874.         } break;
  875. case 13:
  876. {
  877. # ifdef DEBUG
  878.         if(debug) sect2dump();
  879. # endif
  880.         } break;
  881. case 14:
  882. {    yyval = mn0(yypvt[-0]); } break;
  883. case 15:
  884. {
  885.         p = yypvt[-0];
  886.         i = mn0(*p++);
  887.         while(*p)
  888.             i = mn2(RSTR,i,*p++);
  889.         yyval = i;
  890.         } break;
  891. case 16:
  892. {    symbol['\n'] = 0;
  893.         if(psave == FALSE){
  894.             p = ccptr;
  895.             psave = ccptr;
  896.             for(i=1;i<'\n';i++){
  897.                 symbol[i] = 1;
  898.                 *ccptr++ = i;
  899.                 }
  900.             for(i='\n'+1;i<NCH;i++){
  901.                 symbol[i] = 1;
  902.                 *ccptr++ = i;
  903.                 }
  904.             *ccptr++ = 0;
  905.             if(ccptr > ccl+CCLSIZE)
  906.                 error("Too many large character classes");
  907.             }
  908.         else
  909.             p = psave;
  910.         yyval = mn1(RCCL,p);
  911.         cclinter(1);
  912.         } break;
  913. case 17:
  914. {    yyval = mn1(RCCL,yypvt[-0]); } break;
  915. case 18:
  916. {    yyval = mn1(RNCCL,yypvt[-0]); } break;
  917. case 19:
  918. {    yyval = mn1(STAR,yypvt[-1]); } break;
  919. case 20:
  920. {    yyval = mn1(PLUS,yypvt[-1]); } break;
  921. case 21:
  922. {    yyval = mn1(QUEST,yypvt[-1]); } break;
  923. case 22:
  924. {    yyval = mn2(BAR,yypvt[-2],yypvt[-0]); } break;
  925. case 23:
  926. {    yyval = mn2(RCAT,yypvt[-1],yypvt[-0]); } break;
  927. case 24:
  928. {    if(!divflg){
  929.             j = mn1(S2FINAL,-casecount);
  930.             i = mn2(RCAT,yypvt[-2],j);
  931.             yyval = mn2(DIV,i,yypvt[-0]);
  932.             }
  933.         else {
  934.             yyval = mn2(RCAT,yypvt[-2],yypvt[-0]);
  935.             warning("Extra slash removed");
  936.             }
  937.         divflg = TRUE;
  938.         } break;
  939. case 25:
  940. {    if(yypvt[-3] > yypvt[-1]){
  941.             i = yypvt[-3];
  942.             yypvt[-3] = yypvt[-1];
  943.             yypvt[-1] = i;
  944.             }
  945.         if(yypvt[-1] <= 0)
  946.             warning("Iteration range must be positive");
  947.         else {
  948.             j = yypvt[-4];
  949.             for(k = 2; k<=yypvt[-3];k++)
  950.                 j = mn2(RCAT,j,dupl(yypvt[-4]));
  951.             for(i = yypvt[-3]+1; i<=yypvt[-1]; i++){
  952.                 g = dupl(yypvt[-4]);
  953.                 for(k=2;k<=i;k++)
  954.                     g = mn2(RCAT,g,dupl(yypvt[-4]));
  955.                 j = mn2(BAR,j,g);
  956.                 }
  957.             yyval = j;
  958.             }
  959.     } break;
  960. case 26:
  961. {
  962.         if(yypvt[-1] < 0)warning("Can't have negative iteration");
  963.         else if(yypvt[-1] == 0) yyval = mn0(RNULLS);
  964.         else {
  965.             j = yypvt[-2];
  966.             for(k=2;k<=yypvt[-1];k++)
  967.                 j = mn2(RCAT,j,dupl(yypvt[-2]));
  968.             yyval = j;
  969.             }
  970.         } break;
  971. case 27:
  972. {
  973.                 /* from n to infinity */
  974.         if(yypvt[-2] < 0)warning("Can't have negative iteration");
  975.         else if(yypvt[-2] == 0) yyval = mn1(STAR,yypvt[-3]);
  976.         else if(yypvt[-2] == 1)yyval = mn1(PLUS,yypvt[-3]);
  977.         else {        /* >= 2 iterations minimum */
  978.             j = yypvt[-3];
  979.             for(k=2;k<yypvt[-2];k++)
  980.                 j = mn2(RCAT,j,dupl(yypvt[-3]));
  981.             k = mn1(PLUS,dupl(yypvt[-3]));
  982.             yyval = mn2(RCAT,j,k);
  983.             }
  984.         } break;
  985. case 28:
  986. {    yyval = mn2(RSCON,yypvt[-0],yypvt[-1]); } break;
  987. case 29:
  988. {    yyval = mn1(CARAT,yypvt[-0]); } break;
  989. case 30:
  990. {    i = mn0('\n');
  991.         if(!divflg){
  992.             j = mn1(S2FINAL,-casecount);
  993.             k = mn2(RCAT,yypvt[-1],j);
  994.             yyval = mn2(DIV,k,i);
  995.             }
  996.         else yyval = mn2(RCAT,yypvt[-1],i);
  997.         divflg = TRUE;
  998.         } break;
  999. case 31:
  1000. {    yyval = yypvt[-1]; } break;
  1001. case 32:
  1002. {    yyval = mn0(RNULLS); } break;
  1003.         }
  1004.         goto yystack;  /* stack new state and value */
  1005.  
  1006.     }
  1007.